from dataclasses import dataclass
from datetime import datetime
from decimal import Decimal
from typing import Optional, Dict, Any

@dataclass
class Event:
    """事件基类"""
    timestamp: datetime
    type: str

@dataclass
class MarketEvent(Event):
    """市场数据事件"""
    exchange: str
    symbol: str
    data: Dict[str, Any]

@dataclass
class SignalEvent(Event):
    """交易信号事件"""
    exchange: str
    symbol: str
    signal_type: str  # entry/exit
    side: str  # long/short
    price: Decimal
    strength: float

@dataclass
class OrderEvent(Event):
    """订单事件"""
    exchange: str
    symbol: str
    order_type: str  # market/limit
    side: str  # buy/sell
    amount: Decimal
    price: Optional[Decimal] = None
    stop_price: Optional[Decimal] = None
    take_profit: Optional[Decimal] = None
    stop_loss: Optional[Decimal] = None
    leverage: float = 1.0

@dataclass
class FillEvent(Event):
    """成交事件"""
    exchange: str
    symbol: str
    order_type: str
    side: str
    amount: Decimal
    price: Decimal
    commission: Decimal
    leverage: float = 1.0
